package com.whj.wkpt.service;

import com.whj.wkpt.entity.Payment;
import com.whj.wkpt.mapper.PaymentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class PaymentService {

    @Autowired
    private PaymentMapper paymentMapper;

    public Payment createPayment(Payment payment) {
        payment.setCreateTime(LocalDateTime.now());
        payment.setUpdateTime(LocalDateTime.now());
        paymentMapper.insert(payment);
        return payment;
    }

    public Payment updatePayment(Payment payment) {
        payment.setUpdateTime(LocalDateTime.now());
        paymentMapper.update(payment);
        return payment;
    }

    public Payment findById(Long paymentId) {
        return paymentMapper.findById(paymentId);
    }

    public List<Payment> findAllPayments() {
        return paymentMapper.findAll();
    }

    public List<Payment> findByTaskId(Long taskId) {
        return paymentMapper.findByTaskId(taskId);
    }
}